package com.mall.user.dto;

import com.mall.commons.result.AbstractRequest;
import com.mall.commons.tool.exception.ValidateException;
import com.mall.user.constants.SysRetCodeConstants;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Pattern;

/**
 *  cskaoyan
 * create-date: 2019/7/23-12:48
 */
@Data
public class UserRegisterRequest extends AbstractRequest {

    private String userName;
    private String userPwd;
    private String email;

    @Override
    public void requestCheck() {
        if(StringUtils.isBlank(userName)||StringUtils.isBlank(userPwd)||StringUtils.isBlank(email)||(!Pattern.matches("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$",email)))
        {
            throw new ValidateException(SysRetCodeConstants.EMAIL_FORMAT_ERROR.getCode(),SysRetCodeConstants.EMAIL_FORMAT_ERROR.getMessage());
        }
    }
}
